package com.pay.game.central.web.mapper;

import com.pay.game.central.web.bean.TelegramBill;
import com.pay.game.central.web.bean.TelegramCard;
import com.pay.game.central.web.bean.TelegramGroup;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BotMapper {

    @Insert("insert into telegram_group(`id`,`group_name`,`group_comment`)" +
            " values(#{id},#{group_name},#{group_comment})")
    void addTelegramGroup(TelegramGroup telegramGroup);

    @Delete("delete from telegram_group where id=#{id}")
    void deleteTelegramGroup(@Param("id") String id);

    @Update("update telegram_card set telegram_group_id='' where telegram_group_id=#{groupId}")
    void removeTelegramCardGroup(@Param("groupId") String groupId);

    @Select("select * from telegram_group")
    List<TelegramGroup> listGroup();

    @Insert("insert into telegram_bill(`id`,`time`,`value`,`real_name`,`card_id`)" +
            " values(#{id},#{time},#{value},#{real_name},#{card_id})")
    void addTelegramBill(TelegramBill bill);

    @Select("select * from telegram_bill order by time desc")
    List<TelegramBill> listTelegramBill();

    @Insert("insert into telegram_card(`id`,`real_name`,`telegram_group_id`)" +
            " values(#{id},#{real_name},#{telegram_group_id})")
    void addTelegramCard(TelegramCard telegramCard);

    @Select("select tc.*,tg.group_name telegram_group_name from telegram_card tc" +
            " left join telegram_group tg on tc.telegram_group_id=tg.id" +
            " order by tc.status desc")
    List<TelegramCard> listTelegramCard();

    @Update("update telegram_card set status=-1 where id=#{id}")
    void disableCard(String id);

    @Update("update telegram_card set status=0, deviceId='' where id=#{id}")
    void unbindCard(String id);

    @Update("update telegram_card set status=1, deviceId=#{deviceId} where real_name=#{realName}")
    void bindCard(@Param("realName") String realName,@Param("deviceId")  String deviceId);

    @Select("select real_name, deviceId, id, telegram_group_id, status from telegram_card where real_name=#{realName}")
    TelegramCard getCardInfo(@Param("realName") String realName);

}
